﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace _052.TCP服务器端TcpServer
{
	internal class Program
	{
		static void Main(string[] args)
		{
			// IP 地址  Port端口号  内网=局域网 外网
			// ipv4   流的形式  TCP协议
			Socket tcpServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
			// 10.34.200.36
			IPAddress iPAddress = new IPAddress(new byte[] { 10, 34, 200, 36 });

			// IP + Port
			IPEndPoint iPEndPoint = new IPEndPoint(iPAddress, 7788);

			tcpServer.Bind(iPEndPoint);
			tcpServer.Listen(100);
            Console.WriteLine("开始接客了");
            // 客户端Socket
            Socket client = tcpServer.Accept();
            Console.WriteLine("一个客户端连接过来了");
			byte[] data = new byte[1024];
			int length = client.Receive(data);
			// 二进制变字符
			string message = Encoding.UTF8.GetString(data, 0, length);
            Console.WriteLine("接受到客户端消息："+message);

			// 想客户端发送消息
			client.Send(Encoding.UTF8.GetBytes("来了随便坐"));


			client.Close();
			tcpServer.Close();

		}
	}
}
